/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.service.ro.impl;

import java.util.List;

import com.us.usws.dao.BoxThemeDAO;
import com.us.usws.dao.MeetingDAO;
import com.us.usws.dao.VideoDAO;
import com.us.usws.dao.VideoFileDAO;
import com.us.usws.model.domain.box.BoxTheme;
import com.us.usws.model.domain.video.Video;
import com.us.usws.service.ro.BoxThemeROService;

/**
 * Service RO impl class
 * @author robot
 */
public class BoxThemeROServiceImpl implements BoxThemeROService {

	/**
	 * DAO instance
	 */
	private BoxThemeDAO dao = new BoxThemeDAO();
	private VideoDAO vDao = new VideoDAO();
	private MeetingDAO mDao = new MeetingDAO();
	private VideoFileDAO fDao = new VideoFileDAO();

	/**
	 * Get Count.
	 */
	@Override
	public int getTotalCount() {
		return dao.getTotalCount();
	}

	/**
	 * Get all list.
	 */
	@Override
	public List<BoxTheme> getAllBoxThemes() {
		return dao.getAllBoxThemes();
	}

	/**
	 * Get all list by pagination.
	 */
	@Override
	public List<BoxTheme> getBoxThemes(int start, int end) {
		return dao.getBoxThemes(start, end);
	}

	/**
	 * Get BoxTheme by primary key.
	 */
	@Override
	public BoxTheme getBoxTheme(String uid) {
		BoxTheme b = dao.getBoxTheme(uid);
		return fillProps(b);
	}

	/**
	 * fill props
	 * @param theme
	 * @return
	 */
	private BoxTheme fillProps(BoxTheme theme) {
		theme.setVideos(vDao.getThemeVideos(theme.getUid()));
		if (theme.getVideos() != null) {
			for (Video v : theme.getVideos()) {
				v.setVideoFile(fDao.getVideoFile(v.getFileUid()));
			}
		}
		theme.setMeetings(mDao.getThemeVideos(theme.getUid()));
		return theme;
	}
}